#include <bits/stdc++.h>

using namespace std;
const int INF=1000000010;
int main_1101_1()
{
    int N;
    scanf("%d",&N);
    set<int> ans;
    int leftMax[N+1],rightMin[N+1],seq[N+1];
    seq[0]=leftMax[0]=0;
    for (int i=1; i<=N ; ++i )
    {
        scanf("%d",&seq[i]);
        leftMax[i]=max(leftMax[i-1],seq[i-1]);
    }
    rightMin[N]=INF;
    for (int i=N-1; i>0 ; --i )
    {
        rightMin[i]=min(rightMin[i+1],seq[i+1]);
    }
    for (int i=1; i<=N ; ++i )
    {
        if (seq[i]>leftMax[i]&&seq[i]<rightMin[i])
        {
            ans.insert(seq[i]);
        }
    }
    printf("%lld\n",ans.size());
    if (!ans.empty())
    {

        for (set<int>::iterator it=ans.begin(); it!=--ans.end() ; ++it)
        {
            printf("%d ",*it);
        }
        printf("%d",*--ans.end());
    }else
    {
        printf("\n");
    }
    return 0;
}
